﻿<!DOCTYPE html> 
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<link href="${root!}/lib/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
<link href="${root!}/lib/ligerUI/skins/ligerui-icons.css" rel="stylesheet" type="text/css" />
<link href="${root!}/lib/css/orders.css"rel="stylesheet"  type="text/css" />
<script src="${root!}/lib/jquery/jquery-1.3.2.min.js" type="text/javascript"></script>
<script src="${root!}/lib/ligerUI/js/core/base.js" type="text/javascript"></script>
<script src="${root!}/lib/ligerUI/js/plugins/ligerToolBar.js" type="text/javascript"></script>
<script src="${root!}/lib/ligerUI/js/ligerui.all.js" type="text/javascript"></script>
<script src="${root!}/lib/ligerUI/js/plugins/ligerForm.js"></script>
<script src="${root!}/lib/ligerUI/js/plugins/ligerTip.js" type="text/javascript"></script>
<script src="${root!}/lib/jquery-validation/jquery.validate.min.js"></script>
<script src="${root!}/lib/jquery-validation/jquery.metadata.js" type="text/javascript"></script>
<script src="${root!}/lib/jquery-validation/messages_cn.js" type="text/javascript"></script>
<script src="${root!}/lib/js/orders.js"></script>
<script> 
var groupicon = "${root!}/lib/ligerUI/skins/icons/communication.gif";
var search2 = '${root!}/lib/ligerUI/skins/icons/search2.gif';
var role = '${root!}/lib/ligerUI/skins/icons/role.gif';
var cancle = '${root!}/lib/ligerUI/skins/icons/cancle.gif';
var g = null;
var s = null;

var h_status = [{value: "0", text: "无效"},
                {value: "1", text: "已下单"},
                {value: "2", text: "已发货"},
                {value: "3", text: "已评价"}];
$(function (){
	/**工具栏*/	
	$("#toptoolbar").ligerToolBar({ items: [
		{ text: '查询', click: f_search,icon:'search2'},
		{ line:true },
		{ text: '送餐', click: f_shipment,icon:'role'},
		{ line:true },
		{ text: '设置订单无效', click: f_invalid,icon:'cancle'}
	]});
	
	$(function (){
		$("#layout").ligerLayout({ leftWidth: 200});
	});
	
	
 
	//<!--DataGrid-->
	 g = $("#grid").ligerGrid({
		columns: [
			  { display: '订单头ID', name: 'ORDER_HEAD_ID',width: 150, align: 'left',hide: 1} ,
			  { display: '客户ID', name: 'ACCOUNT_ID',width: 150, align: 'center' },
			  { display: '收货人', name: 'ACCOUNT_NAME',width: 150, align: 'center' },
			  { display: '地址', name: 'ADDRESS',width: 150, align: 'center' },
			  { display: '电话/手机', name: 'PHONE',width: 150, align: 'center' },
			  { display: '状态', name: 'STATUS',width: 100, align: 'center',
				render: function(rowdata, index, value){
					if(value == '1')
						return "已下单";
					else if(value == '2')
						return "已发货";
					else if(value == '3')
						return "已评价";
					else if(value == '0')
						return "无效";
					else return value;
				}},
			  { display: '下单时间', name: 'CREATE_DATE', align: 'center', width: 150, minWidth: 120},
			  { display: '最后更新人', name: 'UPDATE_NAME', align: 'center', width: 150, minWidth: 120},
			  { display: '最后更新时间', name: 'LAST_UPDATE_DATE', align: 'center', width: 150, minWidth: 120}
		], 		
		url: '${root!}/sys/order/getOrderJson', 
		pageSize: 5, 
		pageSizeOptions: [1, 2, 5, 10, 15, 20, 25],
		method:"post",
		width : '99%',
		height : '98%',
		rowHeight : 30,
		rownumbers : true,
		checkbox : true,
		frozen : false,
		enabledSort: true,
		alternatingRow:false,
		alternatingRow: true,
		sortName:'create_date',
		parms:[{name:"id",value:'0'}],
		detail : {
			onShowDetail : f_showDetail,
			height : 'auto'
		}	
		}); 
	
	 //查询
	 s = $('#search').ligerForm({
		 inputWidth: 200, 
		 lableWidth: 400, 
		 space: 20,
		 fields:[
		        {display: "检索开始时间", name: "create_date_l",type: 'date', width: 150, group: "查询条件",groupicon: groupicon},
		        {display: "检索结束时间", name: "create_date_r",type: 'date',newline: false, width: 150},
		        {display: "订单状态", name: "status", width: 150, newline: true, type: "combobox",
		        	options : {
		        		valueField : 'value',
		        		textField : 'text',
		        		data : h_status,
		        		value : 1
		        	}	
		        },
		        {display: "收货人", name: "account_name", width: 150, newline: false}
		        ],
	 });
	 $('#search').hide();
});
//查询
function f_search(){
	var filtercontainer = $("#search").width(500).height(150).hide();
	$.ligerDialog.open({
		width: 560,
		height: 230,
		target: filtercontainer,
		isReset: true,
		title: '检索订单',
		top : 50,
		buttons: [{text: '确定', 
					onclick: function(item, dialog){
						g.setOptions({newPage:1});
						loadData();
						clear();
						dialog.hide();
					}},
		         {text: '取消', 
					onclick: function(item, dialog){
		        				clear();
		        				dialog.hide();
		        				}
					}]
	});
}
//送餐
function f_shipment(){
	var rows = g.getSelectedRows();
	if(rows.length == 0){
		$.ligerDialog.warn("请选择一行数据");
		return;
	}
	//拼接所选订单id
	var orderIds = "";
	for(var i=0; i<rows.length; i++){
		orderIds += rows[i].ID + ",";
	}
	orderIds = orderIds.substring(0, orderIds.length-1);
	$.ajax({
		type : 'post',
		url : '/sys/order/doShipment',
		data : {'ids': orderIds},
		dataType : 'json',
		async : false,
		success : function(data, textStatus){
			$.ligerDialog.success(data.msg);
			g.loadData();
		}
	});
}
//设置订单无效
function f_invalid(){
	var rows = g.getSelectedRows();
	if(rows.length == 0){
		$.ligerDialog.warn('请至少选择一行订单');
		return;
	}
	//拼接所选订单id
	var orderIds = "";
	for(var i=0; i<rows.length; i++){
		if(rows[i].STATUS == 0){
			$.ligerDialog.warn('已含有无效订单，请重新选择');
			return;
		}
		orderIds += rows[i].ID + ",";
	}
	$.ligerDialog.confirm('确定要设置 ' + rows.length + ' 行订单无效？', function(yes){
		if(yes == true){
			orderIds = orderIds.substring(0, orderIds.length-1);
			$.ajax({
				type : 'post',
				data : {'orderHeadIds' : orderIds},
				dataType : 'json',
				url : '/sys/order/doInvalid',
				success : function(data, textStatus){
					var tip = $.ligerDialog.tip({title : '操作提示', content : data.msg});
					//刷新页面
					g.loadData();
					//弹出提示
					setTimeout(function(){tip.close();}, 2500);
				}
			});
		}
	});
}

//显示订单详情
function f_showDetail(row, detailPanel, callback){
	var dishs = getOrderDish(row);
	$(detailPanel).append(dishs);
}
//获取订单详情
function getOrderDish(row){
	var items;
	var sum = 0;
	$.ajax({
		type : 'post',
		async : false,
		data : {'orderHeadId' :　row.ID},
		dataType : 'json',
		url : '/sys/order/getDetailByOrderHeadId',
		success : function(data){
			//转换json对象（两种方法）
			//var json = JSON.parse(data);
			//var json = eval('(' + data + ')'); 
			items = data.items;
		}
		
	});
	var tableInfo = "<table style='width:100%;' class='detailInfo'>" + 
					"<thead><tr class='font:14pt #f9fafc;'><th colspan='8'>订单信息↓</th></tr>" +
					"<tr>" +
						"<th style='width:60px'>菜品名</th>" + 
						"<th style='width:60px'>菜系名</th>" + 
						"<th style='width:40px'>单价</th>" + 
						"<th style='width:40px'>数量</th>" + 
						"<th style='width:40px'>小计</th>" + 
						"<th style='width:40px'>等级</th>" + 
						"<th style='width:60px'>评价</th>" + 
					"</tr></thead>" + 
					"<tbody>";
	for(var i=0; i<items.length; i++){
		tableInfo += "<tr>" +
						"<th>" + items[i].dish_name + "</th>" + 
						"<th>" + items[i].cuisine_name + "</th>" + 
						"<th>" + items[i].price + "</th>" + 
						"<th>" + items[i].quantity + "</th>" + 
						"<th>" + items[i].quantity*items[i].price + "</th>" +
						"<th>" + items[i].grade + "</th>";
		var evaluation = items[i].evaluation;
		if(evaluation.length > 22){
			evaluation = evaluation.substring(0, 10) + '...';
		}
		tableInfo += 	"<th title=" + items[i].evaluation + ">" + evaluation + "</div></th>" + 
					"</tr>";
		sum += items[i].quantity*items[i].price;
	}				
	tableInfo += "</tbody></table>";
	tableInfo += "</tbody><tfoot>";
	tableInfo += "<tr><td colspan='8' style='color:#0066FF;'>金额：" + sum + "</td></tr>";
	tableInfo += "</tfoot></table>";
	//tableInfo = "<div style='margin:0 0 1% 0;'>"+tableInfo+"</div>";	
	var dishs = $(tableInfo);
	return dishs;
}
//加载数据
function loadData(){
	var sdata = s.getData();
	g.set('parms', { where: $.ligerui.toJSON(sdata)});
	g.loadData();
} 
//清除查询条件
function clear(){
	var data = {'create_date_l':'','create_date_r':'','account_name':''};
	s.setData(data);
}
function f(){}
</script>
<style type="text/css"> 
	body{ padding:0px; margin:0; overflow:hidden;}
	#layout{  width:100%;margin:0; padding:0;  }  
	.l-page-top{ height:80px; background:#f8f8f8; margin-bottom:3px;}
	.tree{
		width:200px;
		height:600px;
		margin: 0px;
		border: 1px solid #ccc;
		overflow: scroll;}
</style>
</head>
<body>

<div id="layout">
	<!--工具栏-->
	<div id="toptoolbar" style="padding:3px; overflow:hidden;" ></div>
	<div id="grid"></div>
</div> 
<!-- 查询 -->
<div style="display:none" id="search"></div>
</body>
</html>
